package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain.Sign;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.service.IIntegralService;
import cn.wolfcode.trip.base.service.ISignService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * 登录相关的控制器
 */
@Controller
public class SignController {
    @Autowired
    private ISignService signService;
    @Autowired
    private IIntegralService integralService;
    @Autowired
    private IUserService userService;
    @PostMapping("/sign")
    @ResponseBody
    public Object sign() {
        JSONResult jsonResult = new JSONResult();
        User user = UserContext.getCurrentUser();
        try {
            if (user == null) {
                throw new Exception("网络异常");
            }
            //签到操作
            Sign sign = signService.sign(user);
            //签到赠送积分
            integralService.sign(sign);
            jsonResult.setData(sign);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.mark(e.getMessage());
        }
        return jsonResult;
    }
}
